package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.IuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class TestController {
    @Autowired
    IuserService iuserService;
    @GetMapping("/all")
    public ModelAndView all(ModelAndView model) {
        // 查询用户
//        User user = new User(1, "小米", "搭建等");
//        List<User> users = new ArrayList<>();
//        users.add(user);
//        users.add(user);
        List<User> all = iuserService.findAll();
        // 放入模型
        model.addObject("users", all);
        model.setViewName("user");
        // 返回模板名称（就是classpath:/templates/目录下的html文件名）
        return model;
    }
}
